package com.hpjpw.idoapp.controller;

import com.hpjpw.idoapp.domain.TaskImportVo;
import com.hpjpw.idoapp.service.TaskImportService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api("实习宝藏任务导入")
@RestController()
@RequestMapping("/ido/task/import")
public class TaskImportController {
    @Autowired
    TaskImportService taskImportService;

    @ApiOperation("导入实习宝藏任务")
    @Log(title = "导入实习宝藏任务" , businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<TaskImportVo> util = new ExcelUtil<>(TaskImportVo.class);
        List<TaskImportVo> taskImportVoList = util.importExcel(file.getInputStream());
        String message = taskImportService.importTask(taskImportVoList);
        return AjaxResult.success(message);
    }

    @ApiOperation("获取实习宝藏任务导入模板")
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate() {
        ExcelUtil<TaskImportVo> util = new ExcelUtil<>(TaskImportVo.class);
        return util.importTemplateExcel("实习宝藏任务导入模板");
    }
}
